package com.tgslc.defaultmanagement.serviceDelegate.borrower;

import com.tgslc.defaultmanagement.domain.Borrower;

import java.util.ArrayList;
import java.util.List;

public class BorrowerServiceDelegate {

  private Borrower borrower;
  private List<Borrower> borrowerList;

  public void setBorrower(Borrower borrower) {
    this.borrower = borrower;
  }

  public Borrower getBorrower() {
    return borrower;
  }

  public void setBorrowerList(List<Borrower> borrowerList) {
    this.borrowerList = borrowerList;
  }

  public List<Borrower> getBorrowerList() {
    return borrowerList;
  }

  public void fetchBorrowersList() {
    List<Borrower> list = new ArrayList<Borrower>();

    Borrower obj = new Borrower();
    obj.setBorrowerId(123L);
    obj.setBorrowerName("TOM");
    list.add(obj);

    obj = new Borrower();
    obj.setBorrowerId(456L);
    obj.setBorrowerName("HARRY");
    list.add(obj);

    this.borrowerList = list;
  }

  public void fetchBorrowerDetials(Long borrowerId) {

    List<Borrower> list = this.getBorrowerList();

    if (list == null) {
      this.fetchBorrowersList();
    }

    for (int i = 0; i < list.size(); i++) {
      if (list.get(i).getBorrowerId().equals(borrowerId)) {
        this.borrower = list.get(i);
        break;
      }
    }
  }
}
